package com.hzcx.app.simplechat.ui.friend.adapter;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.friend.bean.FriendBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendLableListBean;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;

import java.util.ArrayList;
import java.util.List;

public class NewFriendAdapter extends BaseQuickAdapter<FriendBean, BaseViewHolder> {

    private OnFriendListItemOnClickListener listener;

    private int tag;

    public NewFriendAdapter(@Nullable List<FriendBean> data) {
        super(R.layout.rv_item_friend_header, data);
    }

    public NewFriendAdapter(@Nullable List<FriendBean> data, int tag) {
        super(R.layout.rv_item_friend_header, data);
        this.tag = tag;
    }

    @Override
    protected void convert(BaseViewHolder helper, FriendBean item) {

        TextView tvHeader = helper.getView(R.id.tv_header);
        RecyclerView rvFriendContent = helper.getView(R.id.rv_friend_content);

        List<FriendCityBean> list = new ArrayList<>();
        FriendContentAdapter contentAdapter = new FriendContentAdapter(list, tag);
        rvFriendContent.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));
            rvFriendContent.setAdapter(contentAdapter);
            contentAdapter.setOnItemClickListener((adapter, view, position) -> {
                if (listener != null) {
                    listener.itemOnClick(helper.getAdapterPosition(), position, list.get(position).getMember_id(), list.get(position));
                }
            });

            tvHeader.setVisibility(View.GONE);
            rvFriendContent.setVisibility(View.VISIBLE);
            list.addAll(item.getCity());

    }

    public interface OnFriendListItemOnClickListener {
        void itemOnClick(int headerPos, int contentPos, int id, FriendCityBean bean);
    }

    public void setOnFriendListItemOnClickListener(OnFriendListItemOnClickListener listener) {
        this.listener = listener;
    }
}
